package top.hidoctor.auscultation.feature.activity;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.tang.util.DialogUtil;

import java.util.Arrays;
import java.util.List;

import top.hidoctor.auscultation.R;
import top.hidoctor.auscultation.adapter.ShenheRwbAdapter;
import top.hidoctor.auscultation.adapter.YanebenAdapter;
import top.hidoctor.auscultation.base.BaseActivity;
import top.hidoctor.auscultation.bean.AuditBean;
import top.hidoctor.auscultation.net.c.AuditDetailContract;
import top.hidoctor.auscultation.net.p.AuditDetailPresenter;
import top.hidoctor.auscultation.view.ChooseShenhePop;
import top.hidoctor.auscultation.widget.Player;

public class ShenheRwbDetailActivity extends BaseActivity implements AuditDetailContract.View {
    private RecyclerView recycler;
    private SwipeRefreshLayout refreshLayout;
    private AuditDetailPresenter presenter;
    private String id = "";
    private YanebenAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_shenhe_rwb_detai);
        presenter = new AuditDetailPresenter(this, this);
        id = getIntent().getStringExtra("id");
        initView();
    }

    private void initView() {
        Toolbar toolbar = findViewById(R.id.toolbar);
        TextView tvTitle = findViewById(R.id.tv_title);
        tvTitle.setText("样本列表");
        toolbar.setNavigationIcon(R.mipmap.ic_back_left);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        recycler = findViewById(R.id.recycler);
        recycler.setLayoutManager(new LinearLayoutManager(this));
        recycler.setAdapter(adapter = new YanebenAdapter(R.layout.item_yangben, null, 2));
        recycler.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
        View view = LayoutInflater.from(this).inflate(R.layout.layout_empty_list, (ViewGroup) recycler.getParent(), false);
        adapter.setEmptyView(view);
        getList();

    }

    private void getList() {
        presenter.getDetail(id);
    }

    @Override
    public void getDetailSuc(AuditBean bean) {
        List<AuditBean.SampleBean> sample = bean.getSample();
        adapter.setNewData(sample);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Player currentPlayer = adapter.getCurrentPlayer();
        if (currentPlayer != null) {
            currentPlayer.stop();
        }
    }
}
